package com.shihan.rabbitmq.demo;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.UnsupportedEncodingException;

/**
 * @Description
 * @Author shihan
 * @Date 2020/12/26 16:08
 * @Version 1.0
 */
public class ConsumerApp {

    public static void main(String[] args) throws UnsupportedEncodingException {
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("rabbit-context.xml");

        RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);

        // 主动拉消息的方式
        Message message = rabbitTemplate.receive("queue.qname01");
        System.out.println("接收到的消息为：" + new String(message.getBody(),message.getMessageProperties().getContentEncoding()));

        context.close();

    }

}
